//
//  BankLimitViewController.m
//  YTwallet
//
//  Created by hadrlog on 2019/5/22.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "BankLimitViewController.h"
#import "BankLimitModel.h"
#import "BankLimitTableViewCell.h"
@interface BankLimitViewController()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArr;
@end
@implementation BankLimitViewController


-(void)viewDidLoad{
    self.title = @"限制额度";
    //创建tableView
    [self createTableViee];
    [self queryList];
}
-(void)createTableViee{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ETScreenW, ETScreenH - ETTopHeight - ETTabBarArcHeight) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = ETColorWithRGB(242, 244, 246);
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[BankLimitTableViewCell class] forCellReuseIdentifier:@"cell"];
}
-(void)queryList{
    NSString *url = [[ServerAddressModel shareInstance] fullTAnd0AddrWithParameter:@"/epay_apps/bankCard/showCardAmountInfo"];
    [[ETONEHttpClient sharedInstance] doHTTPSPOST:url Parameters:nil HttpBody:nil SuccessHandler:^(id responseObject) {
        
        NSDictionary *dic = [responseObject mj_JSONObject];
        NSString *code = dic[@"code"];
        if ([@"0000" isEqualToString:code]) {
            [self dealGetReceiptWith:responseObject];
        }
        
    } FailedHandler:^(NSError *error) {
        
    }];
}
-(void)dealGetReceiptWith:(id)response{
    BankLimitModel *bankListResponse = [BankLimitModel mj_objectWithKeyValues:response];
    NSLog(@"%@",bankListResponse);
    for (BankLimitRecord *record in bankListResponse.response.bantAmountInfo) {
        [self.dataArr addObject:record];
    }
    
    [self.tableView reloadData];
   
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BankLimitTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    BankLimitRecord *recod = self.dataArr[indexPath.row];
    cell.titleLab.text = [recod name];
    cell.detailLab.text =  [NSString stringWithFormat:@"单日总额:%@",[recod amountPerDay]];
    cell.timeLab.text = [NSString stringWithFormat:@"单笔限额:%@",[recod amountPerTime]] ;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 65;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
@end
